#!/bin/bash


image="person:godme"
mapping_dir="/data/person/docker-entrypoint-initdb.d"


function run_container(){
    docker-compose down
    docker-compose up -d
}

function build_image(){
    image="person:godme"
    docker rmi -f ${image}
    docker build --rm -t ${image} --build-arg RUNNABLE_JAR=$1 .
}

function init_volumes(){
    mkdir -p ${mapping_dir}
    cp init.sql ${mapping_dir}
    chmod -R a+rw ${mapping_dir}
}
clear
echo "what's your want to do: "
select operation in start_container prepare_image prepare_volumes show_app_logs docker_status exit;
do
    clear
    case ${operation} in 
        "start_container")
            run_container
            ;;
        "prepare_image")
            printf "where is your application jar : "
            read RUNNABLE_JAR
            ls -al $RUNNABLE_JAR
            build_image $RUNNABLE_JAR
            ;;
        "prepare_volumes")
            init_volumes
            ;;
        "docker_status")
            docker ps -a
            ;;
        "show_app_logs")
            docker logs -f person-app
            ;;
         "exit")
            exit 0
            ;;
         "*")
            exit 0
            ;;
    esac
done

